How do I make a firefox extension execute script on page open/load? [migrated]

Posted by Will Mc on Programmers See other posts from Programmers or by Will Mc
Published on 2013-11-04T12:56:29Z Indexed on 2013/11/04 16:10 UTC
Read the original article Hit count: 272

Filed under:
|
|

Thanks in advance!

I am creating my first extension (A firefox extension). See below for full description of final product.

I need help starting off. I have looked and studied the HelloWorld.xpi example found on Mozilla's site so I am happy to edit that to learn. In the example, when you click a menu item it runs script to display an alert message.

My question is, how would I edit this extension to run the script on page load?

I am guessing I need to insert some code in the browserOverlay as it loads on page load so, here is the browserOverlay.xpi from the example I am editing to learn:

    <?xml version="1.0"?>

    <?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
    <?xml-stylesheet type="text/css"
      href="chrome://xulschoolhello/skin/browserOverlay.css" ?>

    <!DOCTYPE overlay SYSTEM
      "chrome://xulschoolhello/locale/browserOverlay.dtd">

    <overlay id="xulschoolhello-browser-overlay"
      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

      <script type="application/x-javascript"
        src="chrome://xulschoolhello/content/browserOverlay.js" />

      <stringbundleset id="stringbundleset">
        <stringbundle id="xulschoolhello-string-bundle"
          src="chrome://xulschoolhello/locale/browserOverlay.properties" />
      </stringbundleset>

      <menubar id="main-menubar">
         <menu id="xulschoolhello-hello-menu" label="&xulschoolhello.hello.label;"
          accesskey="&xulschoolhello.helloMenu.accesskey;" insertafter="helpMenu">
          <menupopup>
            <menuitem id="xulschoolhello-hello-menu-item"
              label="&xulschoolhello.hello.label;"
              accesskey="&xulschoolhello.helloItem.accesskey;"
              oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
          </menupopup>
        </menu>
      </menubar>

      <vbox id="appmenuSecondaryPane">
        <menu id="xulschoolhello-hello-menu-2" label="&xulschoolhello.hello.label;"
          accesskey="&xulschoolhello.helloMenu.accesskey;"
          insertafter="appmenu_addons">
          <menupopup>
            <menuitem id="xulschoolhello-hello-menu-item-2"
              label="&xulschoolhello.hello.label;"
              accesskey="&xulschoolhello.helloItem.accesskey;"
              oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
          </menupopup>
        </menu>
      </vbox>
    </overlay>

I hope you can help me. I need to know what code I should use and where I should put it...

Here is the gist of my overall extension -

I am creating a click to call extension. This extension will search any new page for a phone number whether just refreshed, new page, new tab etc... Each phone number when clicked will open a new tab and direct user to a custom URL.

Thanks again!

© Programmers or respective owner

Related posts about JavaScript

Related posts about Xml